package com.ai.demo.config;

import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.transport.ServerParameters;
import io.modelcontextprotocol.client.transport.StdioClientTransport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;


@Configuration
public class McpSyncClient {
    @Bean(destroyMethod = "close")
    public io.modelcontextprotocol.client.McpSyncClient mcpClient() {
        var stdioParams = ServerParameters.builder("npx.cmd")
                .args("-y", "@wopal/mcp-server-hotnews")
                .build();
        var mcpClient = McpClient.sync(new StdioClientTransport(stdioParams))
                .requestTimeout(Duration.ofSeconds(10)).build();
        var init = mcpClient.initialize();
        System.out.println("MCP Initialized: " + init);
        return mcpClient;
    }
}
